if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_PhieuXuatNhap_DeleteById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_PhieuXuatNhap_DeleteById]
GO
CREATE PROC [sp_PhieuXuatNhap_DeleteById](
	@ID					int
)
AS
BEGIN
	DECLARE @Err		INT
	BEGIN TRANSACTION
		
		--Xoa trong bang chi tiet nhap xuat
		DELETE FROM ChiTietNhapXuat WHERE Ma_phieu_nhap_xuat = @ID
		SET @Err = @@ERROR
		IF @Err <> 0 GOTO PROBLEM
		
		--Xoa trong bang phieu nhap xuat
		DELETE FROM PhieuNhapXuat WHERE ID = @ID
		SET @Err = @@ERROR
		IF @Err <> 0 GOTO PROBLEM
	COMMIT

	PROBLEM:
	IF (@Err <> 0)
	BEGIN
		PRINT 'Unexpected error occurred!'
		ROLLBACK TRANSACTION
	END
	
END
